package com.ja.openchat.ui.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.databinding.FragmentSetPayPwdByPhoneCodeBinding;
import com.ja.openchat.viewmodels.SetPayPwdByPhoneCodeViewModel;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.KLog;

public class SetPayPwdByPhoneCodeFragment extends BaseFragment<FragmentSetPayPwdByPhoneCodeBinding, SetPayPwdByPhoneCodeViewModel> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_set_pay_pwd_by_phone_code;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initViewObservable() {
        viewModel.uc.timerEvent.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                binding.tvCode.setText(s);
                if (getString(R.string.verify_code).equals(s)) {
                    binding.tvCode.setEnabled(true);
                    binding.tvCode.setTextColor(getResources().getColor(R.color.login_btn_bg_color));
                } else {
                    binding.tvCode.setEnabled(false);
                    binding.tvCode.setTextColor(getResources().getColor(R.color.color_text_hint));
                }
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && data != null) {
            String country = data.getStringExtra("country");
            KLog.d(country);
            viewModel.setCountry(country);
        }
    }
}